package leetcode;

import util.ListNode;

/**
 * @Project : AlgorithmLearning
 * @Package : Leetcode
 * @File : Q0019.java
 * @Author : WangRuoyu
 * @Date 2023/11/7 22:35
 */


public class Q0019 {
    public ListNode removeNthFromEnd(ListNode head, int n) {
        ListNode rhead = new ListNode(-1, head);
        ListNode p = rhead;
        ListNode s = rhead;
        while (n-- > 0) {
            s = s.next;
        }
        while (s.next != null) {
            p = p.next;
            s = s.next;
        }
        p.next = p.next.next;
        return rhead.next;
    }

    public static void main(String[] args) {
        Q0019 sl = new Q0019();
    }
}
